package com.maxatime.controller;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.pojo.entity.SysRole;
import com.maxatime.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ssb
 * @since 2024-07-15
 */
@Controller
@RequestMapping("/sysRole")
public class SysRoleController {
    @Autowired
    ISysRoleService isysRoleService;
/**
* @Author 
* @Description 角色查
* @Date  
* @Return 
* @param sysRole
*/
    @RequestMapping("/quest")
    @ResponseBody
    public Map<String,Object> quest(@RequestBody SysRole sysRole){
        Map<String,Object> m = new HashMap<>();
        Map<String,Object> map = isysRoleService.map(sysRole);
        m.put(BusinessContents.CODE, "0000");
        m.put(BusinessContents.MSG, "交易成功");
        m.put(BusinessContents.DATA, map.get("list"));
        m.put("pageInfo", map.get("pageInfo"));
        return m;
    }

    /**
     * @Author
     * @Description 角色增
     * @Date
     * @Return
     * @param
     */
    @RequestMapping("/save")
    @ResponseBody
    public Map<String,Object> save(@RequestBody SysRole sysRole){
        Map<String,Object> m = new HashMap<>();
        isysRoleService.insertSelective(sysRole);
        m.put(BusinessContents.CODE, "1111");
        m.put(BusinessContents.MSG, "新增成功");
        return m;
    }

    /**
     * @Author
     * @Description 角色删除
     * @Date
     * @Return
     * @param
     */
    @RequestMapping("/del")
    @ResponseBody
    public Map<String, Object> del(@RequestBody String jsonStr) {

        JSONObject jsonObj = JSONObject.parseObject(jsonStr);
        int roleId = jsonObj.getInteger("roleId");
        Map<String, Object> m = new HashMap<>();
        isysRoleService.deleteByPrimaryKey(roleId);
        m.put(BusinessContents.CODE, "2222");
        m.put(BusinessContents.MSG, "删除成功");
        return m;
    }
    /**
     * @Author
     * @Description 用户反显
     * @Date
     * @Return
     * @param
     */

    @RequestMapping("/find")
    @ResponseBody
    public Map<String, Object> find(@RequestBody String jsonStr) {
        JSONObject jsonObj = JSONObject.parseObject(jsonStr);
        Map<String, Object> m = new HashMap<>();
        int roleId = jsonObj.getInteger("roleId");
        SysRole find = isysRoleService.find(roleId);
        m.put(BusinessContents.CODE, "3333");
        m.put(BusinessContents.MSG, "反显成功");
        m.put(BusinessContents.DATA, find);
        return m;
    }
    /**
     * @Author
     * @Description 角色修改
     * @Date
     * @Return
     * @param
     */
    @RequestMapping("/update")
    @ResponseBody
    public Map<String, Object> update(@RequestBody SysRole sysRole) {
        Map<String, Object> m = new HashMap<>();
        isysRoleService.updateByPrimaryKeySelective(sysRole);
        m.put(BusinessContents.CODE, "4444");
        m.put(BusinessContents.MSG, "修改成功");
        return m;
    }
}
